package com.dailyblue.java.net.udp;

import lombok.SneakyThrows;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

// 发送方
public class UdpServer {
    @SneakyThrows
    public static void main(String[] args) {
        // 创建udp套接字
        DatagramSocket socket = new DatagramSocket();
        // 创建发送的包裹
        byte[] data = "Hello,world!".getBytes();
        InetAddress address = InetAddress.getLocalHost();
        DatagramPacket packet = new DatagramPacket(data, data.length, address, 8888);
        // 发送
        socket.send(packet);
    }
}
